package com.lysj.bhp.activity.controller;


import com.lysj.bhp.resource.base.ResourceConst;
import com.lysj.bhp.resource.controller.ResourceController;
import com.lysj.bhp.system.base.RootContent;
import com.lysj.bhp.util.web.ParamUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("admin/activity/wangEditor")
public class ActivityWangEditorController extends RootContent {

    @PostMapping("/uploadImages") // 上传本地图片
    public Map<String, Object> uploadImages(MultipartFile[] file) {
        Map<String, Object> respMap = new HashMap<>();
        if (file == null || file.length == 0) {
            respMap.put("errno", -1);//文件找不到错误
            return respMap;
        }
        List<String> dataList = new ArrayList<>();
        String path = ResourceConst.BASE_LOCAL_RESOURCE_IMAGES_DIR + "wang_editor";
        for (int i = 0; i < file.length; i++) {
           StringBuilder sb = new StringBuilder(RootContent.DOMAIN_NAME).append("resource/images/wang_editor/");
//            StringBuilder sb = new StringBuilder("/resource/images/wang_editor/");
            String filename = ParamUtil.uuid();
            String realFileName = ResourceController.fileUpload(file[i], path, filename);
            sb.append(realFileName);
            dataList.add(sb.toString());
        }
        respMap.put("errno", 0);
        respMap.put("data", dataList);
        return respMap;
    }
}
